colobotfandomcom-20200213-history
CBOT Language
The CBOT language is very close in structure and syntax to C++ and Java. It has been adapted for the specific purposes of COLOBOT, and for an efficient pedagogical approach. This language is made up of instructions (see below), blocks, functions, classes, variables, arrays, expressions and conditions. Instructions In the program editor, an instruction in the CBOT language is always displayed on an orange background. If an instruction doesn't have an orange background, this means that it has been misspelled. Instruction names are always written in lower case. Types in the CBOT language The type of a variable appears with a green background. Constants Constants, like categories, are displayed with a red background. Instructions in the CBOT language do ... while You can have do ... while loops. do { // things } while (stuff()); Operators in the CBOT language Specific instructions for bots Instructions about topology Instructions specific to some bots Specific instructions for exchange posts Specific instructions for classes Specific instructions for strings Mathematical Functions Specific instructions for files Tricks and notes See what happens when you try these Some functions to mess around with and see what they do (if they even work): produce - создать объект cmdline ismovie repeat drive Object Properties All objects have at least some of the following properties: * object.category - this is probably so you can do stuff like target.category AlienAnt * object.position * object.orientation - presumably yaw, all angles are in degrees. * object.pitch * object.roll * object.energyLevel - the amount of energy left in the battery, from 1 to 0. Float. May work only on batteries. For robots try robot.energyCell.energyLevel * object.shieldLevel * object.temperature - temperature of the jet engine. 0 is cool, 1 is overheated. * object.altitude - height above the ground. Same as (object.position.z - topo(object.position)) . * object.lifeTime - time since creation of the object. Float. In seconds. * object.energyCell - the object in a robot's battery holder, or none if there's nothing there. * object.load - the entity that the object is carrying, if it's a grabber. Robot Attributes You can get the thing a grabber is holding with this.load. It'll probably be null if there's nothing being held. You can get the entity in the battery slot with this.energyCell. Context Assignment It's possible to have a variable assignment inside of another context, like in C. For example: extern void object::Main() { object target; while ((target = radar()) != null) { // do things } } Note the second parentheses. This example is the equivalent of running: extern void object::Main() { object target = radar(); while (target != null) { // do things target = radar(); } } Limitations You can't use array literals. This won't work: object enemy = radar({AlienAnt, AlienSpider}); Instead, you need to do: object[] enemyClasses = {AlienAnt, AlienSpider}; object enemy = radar(enemyClasses); There's no polymorphism in CBOT, so functions need to be redefined for every type that they might need to work on. Dying Enemies There's no way to tell if an enemy is in the process of dying by looking at its properties, but a dead enemy's lifeTime will no longer go up. See also Types and categories.